package com.platform.boot.security.user.authority;

import com.platform.boot.utils.CriteriaUtils;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.data.relational.core.query.Criteria;

import java.util.List;

/**
 * @author <a href="https://github.com/vnobo">Alex bob</a>
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class UserAuthorityRequest extends UserAuthority {

    @NotNull(message = "权限[authorities]不能为空!")
    private List<String> authorities;

    public static UserAuthorityRequest withUserCode(String userCode) {
        UserAuthorityRequest groupRequest = new UserAuthorityRequest();
        groupRequest.setUserCode(userCode);
        return groupRequest;
    }

    public static UserAuthority of(String userCode, String authority) {
        UserAuthority userAuthority = withUserCode(userCode);
        userAuthority.setAuthority(authority);
        return userAuthority;
    }

    public Criteria toCriteria() {
        return CriteriaUtils.build(this);
    }

}